package user;

import java.util.Scanner;

public class Main {
    private static AdminService adminService = new AdminService();
    private static ManagerService managerService = new ManagerService(adminService);
    private static ReceptionService receptionService = new ReceptionService(managerService);
    private static Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {
        while (true) {
            System.out.println("\n1.经理登录 2.前台登录 3.管理员登录 4.退出");
            System.out.print("选择：");
            String choice = scanner.nextLine();
            switch (choice) {
                case "1":
                    managerLogin();
                    break;
                case "2":
                    receptionLogin();
                    break;
                case "3":
                    adminLogin();
                    break;
                case "4":
                    System.out.println("退出系统");
                    return;
                default:
                    System.out.println("无效选择");
            }
        }
    }

    private static void managerLogin() {
        System.out.print("用户名：");
        String user = scanner.nextLine();
        System.out.print("密码：");
        String pwd = scanner.nextLine();
        User loginUser = adminService.verifyUser(user, pwd, "经理");
        if (loginUser != null) {
            managerService.setCurrentManager(loginUser);
            managerService.showManagerMenu();
        } else {
            System.out.println("登录失败");
        }
    }

    private static void receptionLogin() {
        System.out.print("用户名：");
        String user = scanner.nextLine();
        System.out.print("密码：");
        String pwd = scanner.nextLine();
        User loginUser = adminService.verifyUser(user, pwd, "前台");
        if (loginUser != null) {
            receptionService.setCurrentReception(loginUser);
            receptionService.showReceptionMenu();
        } else {
            System.out.println("登录失败");
        }
    }

    private static void adminLogin() {
        System.out.print("管理员用户名：");
        String user = scanner.nextLine();
        System.out.print("管理员密码：");
        String pwd = scanner.nextLine();
        adminService.login(user, pwd);
        if (adminService.isLoggedIn()) {
            adminService.showAdminMenu();
        }
    }
}